<template>
  <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible="crud.status.cu > 0" :title="crud.status.title" width="700px" @close="dialogClose">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
      <el-form-item label="上级区域" prop="regionParentId">
        <region-tree ref="regionTree" v-model="form.regionParentId" placeholder="请选择上级区域" :node-key="form.regionParentId" />
      </el-form-item>
      <el-form-item label="国家区域编码">
        <el-input v-model="form.countryId" />
      </el-form-item>
      <el-form-item label="区域名称" prop="regionName">
        <el-input v-model="form.regionName" />
      </el-form-item>
      <el-form-item label="区域别名">
        <el-input v-model="form.regionAlias" />
      </el-form-item>
      <el-form-item label="区域标签">
        <tag-select v-model="form.regionTags" :selects="form.regionTags" tag-type="1" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.remark" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="crud.cancelCU">取消</el-button>
      <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { form } from '@crud/crud'
import TagSelect from '@/views/business/common/org/components/TagSelect/index'
import RegionTree from '@/views/business/common/org/components/RegionTree/index'

const defaultForm = { regionId: null, regionParentId: null, countryId: null, regionName: null, regionAlias: null, regionTags: null, remark: null, isNode: null }
export default {
  components: { RegionTree, TagSelect },
  mixins: [form(defaultForm)],
  data() {
    return {
      rules: {
        regionParentId: [{ required: true, message: '父区域ID不能为空', trigger: 'blur' }],
        regionName: [{ required: true, message: '区域名称不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    dialogClose() {
      this.$refs['regionTree'].refresh()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }
</style>
